var King = Piece.extend({
    "$Init":function(_id,_user,_color,_value,_element){
        this.environment.setHistory([]).environment.setMovement([]);
        Piece.$Init.call(this,_id,_user,_color,6,_element);
        main.engine.environment.getTable().environment.getKing().push(this);
        return this;
    },
    "environment":{
        "_color":0, "_element":null, "_history":null, "_id":0, "_movement":null, "_serverTime":0, "_square":null, "_time":0, "_user":0, "_value":6,
        "setColor":function(_value){
            this._setColor(_value);
            return this._parent_;
        },
        "addShield":function(_shield,_threat,_linear,_across){
            console.log("^^^^ Checking movement data of "+_shield.environment.getId()+" for lock.IsLinear?",_linear);
            var move = _shield.environment.getMovement();
            _shield.environment.setMovement([]);
            
            for(var i=0, len=move.length; i<len; i++){
                console.log("^^^^ Move: "+move[i].environment.getX()+"x"+move[i].environment.getY());
                if(!Table.AxisTest.multi(
                    _threat.environment.getSquare().environment.getX(),
                    _threat.environment.getSquare().environment.getY(),
                    _shield.environment.getSquare().environment.getX(),
                    _shield.environment.getSquare().environment.getY(),
                    move[i].environment.getX(),
                    move[i].environment.getY(),
                    _linear,
                    _across
                )){
                    console.log("^^^^ Axis test result is negative for "+move[i].environment.getX()+"x"+move[i].environment.getY());
                    move[i].cleanRelation(_shield,"Move");
                    this.getShield().push(_shield);
                } else {
                    console.log("^^^^ Axis test result is positive for "+move[i].environment.getX()+"x"+move[i].environment.getY());
                    _shield.environment.getMovement().push(move[i]);
                }
            }
        },
        "cleanShield":function(){
            for(var i=0,len=this.getShield().length; i<len; i++){
                this.getShield()[i].update();
            }
            this.setShield([]);
        },
        "addMove":function(_square){
            if(this.getMovement().indexOf(_square)==-1){
                _square.environment.addMove(this._parent_);
                this.getMovement().push(_square);
            }
            return this._parent_;
        },
        "setSquare":function(_value){
            this.getElement().addStyle({ "left":_value.getLeft()+"px", "top":_value.getTop()+"px" });
            this._setSquare(_value);
            return this._parent_;
        },
        "addThreat":function(_square){
            if(this.getThreat().indexOf(_square)==-1){
                _square.environment.addThreat(this._parent_);
                this.getThreat().push(_square);
            }
            return this._parent_;
        },
        "setValue":function(_value){
            this.getElement().attribute.set("title",Piece.Naming[main.engine.environment.getDefaultLanguage()].name[0]);            
            this._setValue(_value);
            return this._parent_;
        }
    }
});
